package com.hy.dao.impl;
/*
 * @ Date: 2024/5/14 22:31
 * @ Description: ProducertableDaoImpl
 **/

import com.hy.bean.Producertable;
import com.hy.dao.ProducertableDao;
import com.hy.exception.BizException;
import com.hy.utils.DBManager;
import org.apache.commons.dbutils.*;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
@Repository
public class ProducertableDaoImpl implements ProducertableDao {
    private final QueryRunner queryRunner = new QueryRunner();
    BasicRowProcessor basicRowProcessor = new BasicRowProcessor(new GenerousBeanProcessor());
    @Override
    public Producertable queryById(Integer id) {
        return null;
    }

    @Override
    public List<Producertable> queryAllByLimit() {
        Connection connection = null;
        String sql = "select * from producertable";
        try {
            connection = DBManager.getConnection();
            return queryRunner.query(connection,sql,new BeanListHandler<>(Producertable.class,basicRowProcessor));
        }catch(Exception e){
            throw new BizException("数据库连接失败",e);
        }finally {
            try {
                DbUtils.close(connection);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    }

    @Override
    public long count(Producertable producertable) {
        return 0;
    }

    @Override
    public int insert(Producertable producertable) {
        return 0;
    }

    @Override
    public int update(Producertable producertable) {
        return 0;
    }

    @Override
    public int deleteById(Integer id) {
        return 0;
    }
}
